<template>
  <div>
    <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      style="padding-top: 10px"
    >
      <el-menu-item style="padding-left: 30px" @click="clickMenu(item)" v-for="item in menuData" :key="item.name" :index="item.name">
        <i id="icon" :class="`el-icon-${item.icon}`"></i>
        <span slot="title">{{ item.label }}</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<style lang = "less" scoped>
    .el-menu {
        height: 100vh;
    }
    .el-menu-item {
        font-size: 17px;
    }
    .el-menu-item [class^=el-icon-] {
        font-size: 21px;
        margin-right: 8px;
    }
</style>

<script>
export default {
  data() {
    return {
      menuData: [
        {
          path: "/",
          name: "home",
          label: "流管理",
          icon: "s-unfold",
          url: "Home/Home",
        },
        {
          path: "/flv",
          name: "flv",
          label: "演示FLV",
          icon: "monitor",
          url: "flv/flv",
        },
      ],
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    //点击菜单
    clickMenu(item) {
        //当页面的路由与跳转的路由不一致才允许跳转
        if(this.$route.path !== item.path && !(this.$route.path === '/home' && (item.path === '/'))) {
            this.$router.push(item.path)
        }
    }
  },
};
</script>